package com.flower.oss.config;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.flower.oss.adapter.StorageAdapter;
import com.flower.oss.adapter.AliyunStorageAdapter;
import com.flower.oss.adapter.MinioStorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lavender
 * @version 1.0
 * @date 2024-07-11 18:52
 */
@Configuration
@RefreshScope
@EnableAutoConfiguration
public class StorageConfig {

    @Value(value = "${storage.service.type}")
    private String storageType;



    @Bean
    @RefreshScope
    public StorageAdapter storageService()  {
        System.out.println("storageType" + storageType);
        if("minio".equals(storageType)){
            return new MinioStorageAdapter();
        }else if("aliyun".equals(storageType)){
            return new AliyunStorageAdapter();
        }else {

            throw new IllegalArgumentException("为找到对应的文件处理器");
        }
    }
}
